package it.amicosmanettone.whatsimage;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class WarningActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_warning);
		
		Bundle extras = getIntent().getExtras();
			
		String warningText = extras.getString("warningText");
		final int UPGRADE = extras.getInt("UPGRADE", 0);
		
		TextView body = (TextView)findViewById(R.id.warning_text_body);
		
		Typeface moon = Typeface.createFromAsset(getAssets(), "moon.ttf");
		
		body.setText(warningText);

		body.setTypeface(moon);
		body.refreshDrawableState();
		
		Button button_close = (Button)findViewById(R.id.warning_button_close);
		
		if(UPGRADE == 1){
			
			String buttonText = getText(R.string.warning_button_upgrade).toString();
			button_close.setText(buttonText);
			
		}
		
		final Intent main = new Intent(this, MainActivity.class);
		
		button_close.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	if(UPGRADE == 0){
            	
            		main.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            		startActivity(main);
            		overridePendingTransition(R.xml.translate_in, R.xml.translate_out);
            		finish();
        		
            	}
            	else if(UPGRADE == 1){
            		
            		String URL = Configuration.PLAYSTORE_URL;
            		Intent playStore = new Intent(Intent.ACTION_VIEW);
            		playStore.setData(Uri.parse(URL));
            		startActivity(playStore);
            		
            		finish();
            		
            	}
        		
            }
        });
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		return true;
	}
	
	@Override
    public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            
            case android.R.id.home:
                
            	Log.e("WARNING_ACTIVITY", "PREMO BACK");
            	
                return true;
                
            }
            
            return super.onOptionsItemSelected(item);
    }

}
